// pages/yyc/index/index.js
const util = require("../../utils/util.js");
const config = require("../../utils/config.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moveData: null,
    text: "很多人的一生，基本都是自己跟别人较劲，比如别人别人对自己的期待，比如把别人看得太重把自己看得太轻。其实一个人最应该考虑的问题是，自己如何与自己相处，比如人去楼空的时候如何照顾好自己的孤独，比如夜深人静的时候如何跟心灵沟通。自己跟自己能和谐共处，自己跟别人就能相安无事",
    widthScreen: "",
    sliderList: [
      "/images/index/2.jpg",
      "/images/index/1.jpg",
      "/images/index/3.jpg"
    ],
    classData: [], //班级列表
    channel: [{
      name: "我的问卷",
      src: "/images/index/d.png",
      bindtap: "myWenJuan"
    }, {
      name: "我的安排",
      src: "/images/index/b.png",
      bindtap: "myArgument"
    }, {
      name: "我的主题",
      src: "/images/index/a.png",
      bindtap: "myHome"
    }, {
      name: "扫一扫",
      src: "/images/index/c.png",
      bindtap: "saoErCode"
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    util.setBarColor()
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          widthScreen: res.screenWidth
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.rowMove();
    this.getClassData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  /**
   * 水平字母滚动
   */
  rowMove: function() {
    var that = this
    var moveLength = (parseInt(that.data.text.length / 20) + 1) * that.data.widthScreen;
    var continueTime = 25000;
    var setIntervalTime = 2000 + continueTime;
    var animation = wx.createAnimation({
      duration: 5000,
      delay: 0,
      timingFunction: "linear",
    });
    animation.translate((that.data.widthScreen), 0).step({
      duration: 500,
      timingFunction: 'step-start'
    }).translate((-moveLength), 0).step({
      duration: continueTime,
      timingFunction: 'linear'
    })
    that.setData({
      moveData: animation.export()
    })
    setInterval(() => { //间歇调用
      animation.translate((that.data.widthScreen), 0).step({
        duration: 500,
        timingFunction: 'step-start'
      }).translate((-moveLength), 0).step({
        duration: continueTime,
        timingFunction: 'linear'
      })
      that.setData({
        moveData: animation.export()
      })
    }, setIntervalTime)
  },

  /**
   * 得到班级信息
   */
  getClassData: function() {
    var that = this;
    let url = config.BaseUrl + "t/class/userClass";
    let data = {
      "userId": 1
    };
    util.request(url, data, "GET").then(function(res) {
      if (res.code == 200) {
        that.setData({
          classData: res.data
        })
      }
    })
  },

  getList: function() {
    let classData = []
    this.setData({
      classData: classData
    })
  },

  toClassDetail: function(e) {
    wx.navigateTo({
      url: '/pages/index/classDetail/classDetail?classId=' + e.currentTarget.dataset.id + "&className=" + e.currentTarget.dataset.classname,
    })
  },

  myWenJuan:function(){
    wx.navigateTo({
      url: '/pages/index/myWenJuan/myWenJuan',
    })
  },

  myArgument: function () {
    wx.navigateTo({
      url: '/pages/index/myArgument/myArgument',
    })
  },

  myHome: function () {
    wx.navigateTo({
      url: '/pages/index/myHome/myHome',
    })
  },

  saoErCode: function () {
    // 允许从相机和相册扫码
    wx.scanCode({
      success(res) {
        console.log(res)
      }
    })
  },
})